home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.modula2
- Path: mcrcim.mcgill.edu!nyongwa!aliath
- From: aliath@nyongwa.montreal.qc.ca (Michel De Rosa)
- Subject: Re: Modula2 for C programmers?
- Message-ID: <DLIGLJ.FDE@nyongwa.montreal.qc.ca>
- Organization: Radio Free Nyongwa, Montreal (Qc), Canada
- Date: Sun, 21 Jan 1996 03:05:43 GMT
- References: <erico-1801961940460001@infinitehell.cnmat.berkeley.edu> <4dqusf$d7k@weck.brokersys.com>
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- jguthrie@brokersys.com wrote:
- : Eric Obermuhlner (erico@cnmat.berkeley.edu) wrote:
- : : Hi out there
- :
- : : How do I do the ugly things that C programmers like so very much in Modula 2?
- : : Like getting a pointer to a var, pointer arithmetic, bit operations (shift, and, or, exor).
- :
- : Well, I wound up doing that kind of stuff in assembly language. I also
- : concluded that the insistence on abstraction above all else was sometimes
- : detrimental to my efforts to easily write things such as CRC routines.
- :
- Well there are a few reasons why we consider this sort of thing 'ugly'..
- Even so, there should be little need to go to asm for them..
-
- Assigning a pointer to an ordinal variable, would be done thru type
- coercion, as in: ordVar := CARDINAL(ptrVar);
-
- THis assumes, of course, that the length (bit-size) of a CARDINAL is the
- same as for a pointer..
-
- Pointer arith.. ugh!!! well if you *must*, coercing the pointer to a
- cardinal will often do the trick... but if you work on a platform with
- segmented addresses you'll have a lot of fun.. ISO helps, here by providing
- functions for incrementing and decrementing Adresses..
-
- Bit operations.. unfortunately with pre-ISO compilers, we where usually
- stuck with multiplying or dividing by 2, for shift operations (rotate is
- a tad more involved), now ISO also provides functions for those.. for
- and/or/xor etc.. it's always been possible to do these, using the set
- operators.. first coerce to a BITSET, then apply these ops:
-
- + ... set union, 'or'
- * ... set intersection, 'and'
- / ... set symmetric difference, 'xor'
- - ... set difference, 'and not'
-
- Further you can more easily test for a bit, using: bit IN someBitset
-
- Set a specific bit: INCL(someBitset, bitToSet)
- Reset a specific bit: EXCL(someBitset, bitToReset)
-
- Ciao!
- Michel De Rosa
- Aliath@nyongwa.montreal.qc.ca
-